home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / MuManual / C_Sources / FPU.c next >
C/C++ Source or Header  |  1999-10-31  |  6KB  |  210 lines

  1. /*****************************************************************
  2.  ** FPU                                                         **
  3.  **                                                             **
  4.  ** A program similar to the "CPU" program of the workbench     **
  5.  ** used to control some of the flags the FPU offers.           **
  6.  ** This uses the 680x0.library and hence requires the special  **
  7.  ** editions of the 68040.library and related libraries         **
  8.  ** It won't do much on other systems.                          **
  9.  *****************************************************************/
  10.  
  11. /// Includes
  12. #include <exec/types.h>
  13. #include <dos/dos.h>
  14. #include <dos/rdargs.h>
  15. #include <libraries/680x0.h>
  16.  
  17. #include <proto/exec.h>
  18. #include <proto/dos.h>
  19. #include <proto/680x0.h>
  20.  
  21. #include <string.h>
  22. ///
  23. /// Defines
  24. #define ARGS "BSUN/S,NOBSUN/S,INEX/S,NOINEX/S,DIVZ/S,NODIVZ/S,UNFL/S," \
  25.              "NOUNFL/S,OVFL/S,NOOVFL/S,SNAN/S,NOSNAN/S,"               \
  26.              "OPERR/S,NOOPERR/S,NONE/S,ALL/S"
  27.  
  28. #define ARG_BSUN        0L
  29. #define ARG_NOBSUN      1L
  30. #define ARG_INEX        2L
  31. #define ARG_NOINEX      3L
  32. #define ARG_DIVZ        4L
  33. #define ARG_NODIVZ      5L
  34. #define ARG_UNFL        6L
  35. #define ARG_NOUNFL      7L
  36. #define ARG_OVFL        8L
  37. #define ARG_NOOVFL      9L
  38. #define ARG_SNAN        10L
  39. #define ARG_NOSNAN      11L
  40. #define ARG_OPERR       12L
  41. #define ARG_NOOPERR     13L
  42. #define ARG_NONE        14L
  43. #define ARG_ALL         15L
  44.  
  45. #define ARG_COUNT       16L
  46. ///
  47. /// Statics
  48. char version[]="$VER: FPU 40.1 (28.8.99) © THOR";
  49. ///
  50. /// Prototyping
  51. int main(void);
  52. ///
  53.  
  54. /// main
  55. int main(void)
  56. {
  57. struct ExecBase         *SysBase;
  58. struct DosLibrary       *DOSBase;
  59. struct MC680x0Base      *MC680x0Base;
  60. int rc;
  61. ULONG   flags,mask;
  62. struct RDArgs *rd;
  63. LONG    args[ARG_COUNT];
  64.  
  65.         SysBase=*((struct ExecBase **)(4L));
  66.         rc=25;
  67.         memset(args,0,sizeof(args));
  68.  
  69.         if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",36L)) {
  70.          if (rd=ReadArgs(ARGS,args,NULL)) {
  71.           if (MC680x0Base=(struct MC680x0Base *)OpenLibrary("680x0.library",40L)) {
  72.  
  73.            flags=0;
  74.            mask=0;
  75.  
  76.            if (args[ARG_BSUN]) {
  77.                    mask |= FPUCtrlF_BSUN;
  78.            }
  79.            if (args[ARG_NOBSUN]) {
  80.                    mask |= FPUCtrlF_BSUN;
  81.                    flags |= FPUCtrlF_BSUN;
  82.            }
  83.            if (args[ARG_INEX]) {
  84.                    mask |= FPUCtrlF_INEX;
  85.            }
  86.            if (args[ARG_NOINEX]) {
  87.                    mask |= FPUCtrlF_INEX;
  88.                    flags |= FPUCtrlF_INEX;
  89.            }
  90.            if (args[ARG_DIVZ]) {
  91.                    mask |= FPUCtrlF_DIVZ;
  92.            }
  93.            if (args[ARG_NODIVZ]) {
  94.                    mask |= FPUCtrlF_DIVZ;
  95.                    flags |= FPUCtrlF_DIVZ;
  96.            }
  97.            if (args[ARG_UNFL]) {
  98.                    mask |= FPUCtrlF_UNFL;
  99.            }
  100.            if (args[ARG_NOUNFL]) {
  101.                    mask |= FPUCtrlF_UNFL;
  102.                    flags |= FPUCtrlF_UNFL;
  103.            }
  104.            if (args[ARG_OVFL]) {
  105.                    mask |= FPUCtrlF_OVFL;
  106.            }
  107.            if (args[ARG_NOOVFL]) {
  108.                    mask |= FPUCtrlF_OVFL;
  109.                    flags |= FPUCtrlF_OVFL;
  110.            }
  111.            if (args[ARG_SNAN]) {
  112.                    mask |= FPUCtrlF_SNAN;
  113.            }
  114.            if (args[ARG_OPERR]) {
  115.                    mask |= FPUCtrlF_OPERR;
  116.            }
  117.            if (args[ARG_NOOPERR]) {
  118.                    mask |= FPUCtrlF_OPERR;
  119.                    flags |= FPUCtrlF_OPERR;
  120.            }
  121.            if (args[ARG_ALL]) {
  122.                    mask |= FPUCtrlF_OPERR|FPUCtrlF_SNAN|FPUCtrlF_OVFL|
  123.                            FPUCtrlF_UNFL|FPUCtrlF_DIVZ|FPUCtrlF_INEX|
  124.                            FPUCtrlF_BSUN;
  125.                    flags = 0;
  126.            }
  127.            if (args[ARG_NONE]) {
  128.                    mask |= FPUCtrlF_OPERR|FPUCtrlF_SNAN|FPUCtrlF_OVFL|
  129.                            FPUCtrlF_UNFL|FPUCtrlF_DIVZ|FPUCtrlF_INEX|
  130.                            FPUCtrlF_BSUN;
  131.                    flags |= FPUCtrlF_OPERR|FPUCtrlF_SNAN|FPUCtrlF_OVFL|
  132.                            FPUCtrlF_UNFL|FPUCtrlF_DIVZ|FPUCtrlF_INEX|
  133.                            FPUCtrlF_BSUN;
  134.            }
  135.  
  136.            SetFPUExceptions(flags,mask);
  137.            flags = SetFPUExceptions(0L,0L);
  138.  
  139.            Printf("FPU : ");
  140.            switch (FPUType()) {
  141.                    case FPUTYPE_NONE:
  142.                            Printf("no FPU");
  143.                            break;
  144.                    case FPUTYPE_68881:
  145.                            Printf("68881");
  146.                            break;
  147.                    case FPUTYPE_68882:
  148.                            Printf("68882");
  149.                            break;
  150.                    case FPUTYPE_68040:
  151.                            Printf("68040");
  152.                            break;
  153.                    case FPUTYPE_68060:
  154.                            Printf("68060");
  155.                            break;
  156.                    default:
  157.                            Printf("unknown");
  158.                            break;
  159.            }
  160.            Printf(" (");
  161.  
  162.            if (flags & FPUCtrlF_BSUN)
  163.                 Printf("No");
  164.  
  165.            Printf("BSUN ");
  166.  
  167.            if (flags & FPUCtrlF_INEX)
  168.                 Printf("No");
  169.            Printf("INEX ");
  170.  
  171.            if (flags & FPUCtrlF_DIVZ)
  172.                 Printf("No");
  173.            Printf("DIVZ ");
  174.  
  175.            if (flags & FPUCtrlF_UNFL)
  176.                 Printf("No");
  177.            Printf("UNFL ");
  178.  
  179.            if (flags & FPUCtrlF_OVFL)
  180.                 Printf("No");
  181.            Printf("OVFL ");
  182.  
  183.            if (flags & FPUCtrlF_SNAN)
  184.                 Printf("No");
  185.            Printf("SNAN ");
  186.  
  187.            if (flags & FPUCtrlF_OPERR)
  188.                 Printf("No");
  189.            Printf("OPERR");
  190.  
  191.            Printf(")\n");
  192.  
  193.            rc=0;
  194.            CloseLibrary((struct Library *)MC680x0Base);
  195.           } else {
  196.                 Printf("FPU failed: 680x0.library required.\n");
  197.                 rc=20;
  198.           }
  199.           FreeArgs(rd);
  200.          } else {
  201.                 PrintFault(IoErr(),"FPU failed");
  202.                 rc=10;
  203.          }
  204.          CloseLibrary((struct Library *)DOSBase);
  205.         }
  206.  
  207.         return rc;
  208. }
  209. ///
  210.